'use strict';
exports.main = async (event, context) => {
    //event为客户端上传的参数 酒店后台点菜系统的后端代码
    console.log('event : ', event)
    //1、连接数据库
    var db = uniCloud.database();
    //2.接收前端传过来的用户名和密码与数据库里面的用户名和密码对比  查询数据表 user 用户名 密码
        var username = event.username;
        var password = event.password
        var result = await db.collection('login').where({
            username: username
        }).get()
        console.log(result)
        if (result.affectedDocs == 0) {
            //不存在
            return {
                code: 500,
                msg: "用户不存在"
            }
        } else {
            if (password == result.data[0].password) {
                return {
                    code: 200,
                    msg: "登录成功",
                    user: result.data[0]
                }
            } else {
                return {
                    code: 500,
                    msg: "密码错误"
                }
            }
        }
    };
